home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS01.ADF
/
C
/
cc.c
< prev
next >
Wrap
Text File
|
1985-12-04
|
20KB
|
621 lines
/*
Path: puff!uwvax!seismo!lll-crg!lll-lcc!unisoft!fnf
From: fnf@unisoft.UUCP
Subject: cc.c (unix like Lattice C frontend)
Date: 23 Nov 85 07:11:04 GMT
Organization: UniSoft Systems, Berkeley
As I promised in one of my earlier postings, enclosed is the source to my
unix like front end for the Lattice C compiler. This is real useful
for most simple C programs without any amiga specific compilation or
linking requirements.
One of the features of this cc is that your development disk can be in
any drive, including ram, and cc will find it.
Does anyone know of a secret flag to get the Lattice compiler to emit
assembly language? How about a flag to turn off those obnoxious
startup messages (I'm going to patch my compiler if necessary!).
Anyway, hope you find this useful. I was going to post a version of
DECUS grep also, but looks like someone beat me to it.
-Fred (415) 644-1230
*/
/************************************************************************
* *
* Copyright (c) 1985, Fred Fish *
* All Rights Reserved *
* *
* This software and/or documentation is released into the *
* public domain for personal, non-commercial use only. *
* Limited rights to use, modify, and redistribute are hereby *
* granted for non-commercial purposes, provided that all *
* copyright notices remain intact and all changes are clearly *
* documented. The author makes no warranty of any kind with *
* respect to this product and explicitly disclaims any implied *
* warranties of merchantability or fitness for any particular *
* purpose. *
* *
************************************************************************
*/
/*
* cc -- C compiler front end for Amiga and Lattice C.
*
* Somewhat AMIGA/Lattice dependent, but can probably be adapted to
* other systems with a minimum of work. I have attempted to keep
* portability in mind as much as possible.
*
*/
char _sccsid[] = "@(#)cc.c 1.3";
#include <stdio.h>
/*
* The following allow use on systems that don't have my macro based
* debugging package. The default, for now, is to assume it is not
* available.
*/
#ifdef DBUG
# include <local/dbug.h>
#else /* !DBUG */
# define DBUG_ENTER(a)
# define DBUG_RETURN(a) return(a)
# define DBUG_VOID_RETURN return
# define DBUG_2(a,b)
# define DBUG_3(a,b,c)
# define DBUG_4(a,b,c,d)
# define DBUG_5(a,b,c,d,e)
# define DBUG_PUSH(a)
#endif /* DBUG */
/*
* Manifest constants which can be tuned to fit requirements.
*/
#define CMDBUFFERSIZE (256) /* Size of command buffer for CLI command */
#define MAXOPERANDS (64) /* Maximum number of operands on cmd line */
#define MAXDEFINES (32) /* Maximum number of -D<name> args */
#define MAXUNDEFINES (32) /* Maximum number of -U<name> args */
#define MAXINCDIRS (16) /* Maximum number of -I<filename> args */
#define MAXLIBS (16) /* Maximum number of -l<lib> args */
/*
* Define QUADDEV to be the place where you want the compiler
* intermediate files (quad files) to be created. For systems with
* 512K or more, the preferred place is the ram disk. However,
* really big compiles may need to be done on a hard disk.
*/
#define QUADDEV "ram:" /* Keep intermediate files in ram */
/* #define QUADDEV "" */ /* Keep intermediate files in current dir */
/*
* Manifest constants which are generally the same on all systems.
*/
#define EOS '\000' /* End of string character */
/*
* Command line arguments that represent files to be compiled, assembled,
* or linked, are kept track of via an "Operand" array. If, for example,
* the file name is "df0:mydir/junk.c", then the Rootname is
* "df0:mydir/junk", the Basename is "junk", and the Suffix is "c".
* String suffixes are used, rather than single character suffixes, to
* allow use of names with multicharacter suffixes.
*/
struct Operand { /* Info about each operand (non option) */
char *Rootname; /* Name minus any suffix */
char *Basename; /* Name minus any prefix or suffix */
char *Suffix; /* Suffix of operand */
};
static struct Operand Operands[MAXOPERANDS]; /* Table of operands */
static int NOperands = 0; /* Number of operands found */
static char *Defines[MAXDEFINES]; /* Table of defines */
static int NDefines = 0; /* Number of defines */
static char *UnDefines[MAXUNDEFINES]; /* Table of undefines */
static int NUnDefines = 0; /* Number of undefines */
static char *UserInc[MAXINCDIRS]; /* Table of include dirs */
static int NUserInc = 0; /* Number of include dirs */
static char *Libs[MAXLIBS]; /* Table of library args */
static int NLibs = 0; /* Number of library args */
/*
* Macros to determine the suffix type of a file given a pointer to
* its operand structure.
*/
#define CFILE(op) (strcmp(op->Suffix,"c")==0)
#define SFILE(op) (strcmp(op->Suffix,"s")==0)
#define OFILE(op) (strcmp(op->Suffix,"o")==0)
#ifdef AMIGA
# define system(a) (Execute(a,0,0))
# define ENABLE_ABORT (Enable_Abort = 1)
# define DISABLE_ABORT (Enable_Abort = 0)
extern int Enable_Abort; /* Enable abort on CNTL-C */
#else
# define ENABLE_ABORT /* Null expansion */
# define DISABLE_ABORT /* Null expansion */
#endif /* AMIGA */
/*
* Set list of places to search for various executables, libraries, etc.
* Searched in order, first match wins.
*/
static char *Devices[] = {
"",
"ram:",
"df0:",
"df1:",
NULL
};
static char *BinDirs[] = {
"",
"ram:c/",
"df0:c/",
"df1:c/",
NULL
};
static char *LibDirs[] = {
"",
"ram:lib/",
"df0:lib/",
"df1:lib/",
NULL
};
static char *IncDirs[] = {
"ram:include/",
"df0:include/",
"df1:include/",
NULL
};
/*
* Flags set by command line arguments/
*/
static int cflag; /* -c flag given */
static int Pflag; /* -P flag given */
static int Sflag; /* -S flag given */
static int Vflag; /* -V flag given (non-standard) */
static int ErrCount = 0; /* Count of compile/assemble errors */
static char *outfile = "a.out"; /* Output file name from linker */
static char *QuadDev = QUADDEV; /* Where to keep quad files */
static char *Locate (); /* Find a file */
static void Check_Abort (); /* Test for abort requested */
static void Fatal (); /* Quit with fatal error */
static void Warning (); /* Issue warning message */
static void AddOperandToList (); /* Add .c, .s, or .o file to list */
static void MakeObjects (); /* Reduce to list of object files */
static void ParseCommandLine (); /* Deal with command line */
static void Compile (); /* Translate from .c to .o */
static void Assemble (); /* Translate from .s to .o */
static void Link (); /* Gather .o's into executable */
extern void exit (); /* See exit(2) */
main (argc, argv)
int argc;
char *argv[];
{
DBUG_ENTER ("main");
ENABLE_ABORT;
ParseCommandLine (argc, argv);
MakeObjects ();
if (!cflag && !Pflag && !Sflag && ErrCount == 0) {
Link ();
}
DBUG_RETURN (0);
}
/*
* The following macro is used to allow optional whitespace between
* an option and it's argument. Argp is left pointing at the option
* and argv and argc are adjusted accordingly if necessary.
*
* Note that there is no check for missing option arguments. In
* particular, -o -V will blindly take -V as the output file name.
*
*/
#define XARG(argc,argv,argp) {if(*++argp==EOS){argp=(*argv++);argc--;}}
static void ParseCommandLine (argc, argv)
int argc;
char **argv;
{
register char *argp;
DBUG_ENTER ("ParseCommandLine");
argc--;
argv++;
while (argc-- > 0) {
Check_Abort ();
argp = *argv++;
if (*argp != '-') {
AddOperandToList (argp);
} else {
switch (*++argp) {
case '#':
XARG (argc, argv, argp);
DBUG_PUSH (argp);
break;
case 'c':
cflag++;
break;
case 'D':
XARG (argc, argv, argp);
if (NDefines >= MAXDEFINES) {
Fatal ("too many -D args (%d max)", MAXDEFINES);
}
Defines[NDefines++] = argp;
break;
case 'E':
Warning ("-E unimplemented, converted to -P instead");
Pflag++;
break;
case 'f':
break; /* NOP for now, just eat it */
case 'g':
break; /* NOP for now, just eat it */
case 'I':
XARG (argc, argv, argp);
if (NUserInc >= MAXINCDIRS) {
Fatal ("too many -I args (%d max)", MAXINCDIRS);
}
UserInc[NUserInc++] = argp;
break;
case 'l':
XARG (argc, argv, argp);
if (NLibs > MAXLIBS) {
Fatal ("too many -l args (%d max)", MAXLIBS);
}
Libs[NLibs++] = argp;
break;
case 'O':
break; /* NOP for now, just eat it */
case 'o':
XARG (argc, argv, argp);
outfile = argp;
break;
case 'P':
Pflag++;
break;
case 'q':
XARG (argc, argv, argp);
QuadDev = argp;
break;
case 'S':
Sflag++;
Warning ("-S option not yet implemented, ignored");
break;
case 's':
break; /* NOP for now, just eat it */
case 'U':
XARG (argc, argv, argp);
if (NUnDefines >= MAXUNDEFINES) {
Fatal ("too many -U args (%d max)", MAXUNDEFINES);
}
/* how to use the ffp library, text and source */
#ifdef FOOIE
From: bobp@amiga.UUCP (Robert S. Pariseau)
Subject: Amiga Floating Point
Date: 1 Nov 85 04:58:43 GMT
Floating point support exists on the Amiga in several forms for several
purposes. The floating point which is directly supported by expression
evaluation in the V1.0 release Lattice C for the Amiga is a 64 bit software
implementation of the IEEE format. As such, it is *>SLOW<*.
The floating point in ABasiC is a 32
{
fread(buf,sizeof(buf),1,in);
for(i=0,j=0; buf[i] != '\n' && buf[i] != 'Q' && i < sizeof(buf); i++)
{
bytes[j] = (cnv(buf[i++]) << 4);
bytes[j++] |= cnv(buf[i]);
}
write(out,bytes,j);
if (buf[i] == 'Q')
break;
}
fclose(in);
close(out);
}
int cnv(ch)
char ch;
{
if (ch >= '0' && ch <= '9')
return(ch-'0');
else
return((ch-'A')+10);
}
/* value */
putit(j);
break;
case 129: /* ext_ref32 */
case 131: /* ext_ref16 */
case 132: /* ext_ref8 */
for(i=0; i < lbuf; i++)